<?php

$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';

$config = [
    'id' => 'basic',
    'name'=>'yii_shop',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'S99oHV8wdwv8_PVvQWBdeXyLlUR1FZjp',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'app\models\ShopMember',
            'enableAutoLogin' => true,
            'idParam'=>'_user',
            'identityCookie'=>['name'=>'_user_identity','httpOnly'=>true],
            'loginUrl'=>['site/login']
        ],
        'admin' => [
            'class'=>'yii\web\User',
            'identityClass' => 'app\models\Admin',
            'enableAutoLogin' => true,
            'idParam'=>'_admin',
            'identityCookie'=>['name'=>'_admin_identity','httpOnly'=>true],
            'loginUrl'=>['admin/public/login']
        ],

        'errorHandler' => [
            //'errorAction' => 'site/error',
            'class'=> 'app\components\exceptions\ExceptionHandler'
        ],
        //rbac
        'authManager' => [
            'class' => 'yii\rbac\DbManager',
            'itemTable' => 'auth_item',
            'assignmentTable' => 'auth_assignment',
            'itemChildTable' => 'auth_item_child',
            'ruleTable'=>'auth_rule',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' =>false,//这句一定有，false发送邮件，true只是生成邮件在runtime文件夹下，不发邮件
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.163.com',  //每种邮箱的host配置不一样
                'username' => 'rentmaterial@163.com',
                'password' => 'rentmaterial520',
                'port' => '25',
                'encryption' => 'tls',

                           ],
            'messageConfig'=>[
                'charset'=>'UTF-8',
                'from'=>['rentmaterial@163.com'=>'yii2商城']
            ],
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
                [
                    //日志记录方式
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['info'],//日志等级
                    'logVars' =>[],//被收集记录的额外数据如 'logVars' => ['_GET', '_POST', '_FILES', '_COOKIE', '_SESSION','_SERVER'],
                    //指定日志策略
                    'categories' => ['Exception'],
                    //指定日志目录
                    'logFile' => '@app/runtime/logs/exception.log',
                    'maxFileSize' => 1024 * 2,
                    'maxLogFiles' => 100,
                ],
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning','info'],
                    'logVars'=>[],
                    //表示以yii\db\或者app\models\开头的分类都会写入这个文件
                    'categories'=>['yii\db\*','app\models\*'],
                    //表示写入到文件
                    'logFile'=>'@app/runtime/logs/YIISQL_'.date('y_m_d').'.log',
                ],
            ],
        ],
        'db' => $db,
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName'=>false
        ],
    ],
    'params' => $params,
    'modules'=>[
        'admin'=>'app\admin_module\admin'
    ],
    'defaultRoute'=>'index',

];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];
}

return $config;
